package com.tudouji.project.customer.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.customer.domain.Receivableflow;
import com.tudouji.project.customer.service.IReceivableflowService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 账户应收账款流水Controller
 * 
 * @author tudouji
 * @date 2022-05-19
 */
@RestController
@RequestMapping("/customer/receivableflow")
public class ReceivableflowController extends BaseController
{
    @Autowired
    private IReceivableflowService receivableflowService;

    /**
     * 查询账户应收账款流水列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Receivableflow receivableflow)
    {
        startPage();
        List<Receivableflow> list = receivableflowService.selectReceivableflowList(receivableflow);
        return getDataTable(list);
    }

    /**
     * 导出账户应收账款流水列表
     */
    @PreAuthorize("@ss.hasPermi('customer:receivableflow:export')")
    @Log(title = "账户应收账款流水", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Receivableflow receivableflow)
    {
        List<Receivableflow> list = receivableflowService.selectReceivableflowList(receivableflow);
        ExcelUtil<Receivableflow> util = new ExcelUtil<Receivableflow>(Receivableflow.class);
        return util.exportExcel(list, "receivableflow");
    }

    /**
     * 获取账户应收账款流水详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:receivableflow:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(receivableflowService.selectReceivableflowById(guid));
    }

    /**
     * 新增账户应收账款流水
     */
    @PreAuthorize("@ss.hasPermi('customer:receivableflow:add')")
    @Log(title = "账户应收账款流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Receivableflow receivableflow)
    {
        return toAjax(receivableflowService.insertReceivableflow(receivableflow));
    }

    /**
     * 修改账户应收账款流水
     */
    @PreAuthorize("@ss.hasPermi('customer:receivableflow:edit')")
    @Log(title = "账户应收账款流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Receivableflow receivableflow)
    {
        return toAjax(receivableflowService.updateReceivableflow(receivableflow));
    }

    /**
     * 删除账户应收账款流水
     */
    @PreAuthorize("@ss.hasPermi('customer:receivableflow:remove')")
    @Log(title = "账户应收账款流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(receivableflowService.deleteReceivableflowByIds(guids));
    }

    /**
     * 数据初始化
     * 1、	新增初始化批量程序，遍历所有未核销、已出库的、非全款预付的销售订单。
     * 2、	以结算金额生成该订单的应收账款明细数据、并累加应收账款余额。
     */
//    @GetMapping(value = "/dataInit")
    public AjaxResult dataInit()
    {
        return receivableflowService.dataInit();
    }

}
